##############################################
### Deescalating a Trade War (Section 4)   ###
### Authors: Kai Quek and Eddy S. F. Yeung ###
### Date: August 7, 2025                   ###
##############################################

### Set-up ----
## Clean the working environment and set up the working directory
rm(list = ls())
setwd("~/Desktop/trade_reciprocity/replication") # change to your own working directory

## Load the required packages
library(tidyverse)
library(estimatr)
library(cowplot)
library(grid)
library(gridExtra)

## Import the datasets
# American sample
df_US <- read.csv("data_US.csv")
df_US <- subset(df_US, ending_Click.Count > 0) # finished survey
df_US <- subset(df_US, Duration..in.seconds. >= median(df_US$Duration..in.seconds. * .4))

# Chinese sample
df_CN <- read.csv("data_CN.csv")
df_CN$age <- as.numeric(df_CN$yob) + (2023 - 2010 - 1)
df_CN <- df_CN %>% filter(
  citizen == 1,  # Chinese citizen
  age >= 18,     # age >= 18
  Finished == 1, # finished the survey
  (as.numeric(`Duration..in.seconds.`) >= median(as.numeric(`Duration..in.seconds.`)) * .4) # exclude speeders
)

### Recode dependent variables ----
## Main DV: 7-point approval (0 = disapprove strongly; 6 = approve strongly)
df_US <- df_US %>% mutate(approval = case_when(
  trade1d == 1 ~ 0,
  trade1d == 2 ~ 1,
  trade1n == 2 ~ 2,
  trade1n == 3 ~ 3,
  trade1n == 1 ~ 4,
  trade1a == 2 ~ 5,
  trade1a == 1 ~ 6
))

df_CN <- df_CN %>% mutate(approval = case_when(
  trade1d == 1 ~ 0,
  trade1d == 2 ~ 1,
  trade1n == 2 ~ 2,
  trade1n == 3 ~ 3,
  trade1n == 1 ~ 4,
  trade1a == 2 ~ 5,
  trade1a == 1 ~ 6
))

## Additional DV: binary approval (1 = approve; 0 = otherwise)
df_US <- df_US %>% mutate(approval_bin = case_when(
  approval >= 4 & approval <= 6 ~ 1,
  approval >= 0 & approval <= 3 ~ 0,
))

df_CN <- df_CN %>% mutate(approval_bin = case_when(
  approval >= 4 & approval <= 6 ~ 1,
  approval >= 0 & approval <= 3 ~ 0,
))

### Recode moderators ----
## Hawkish (1 = yes; 0 = no)
df_US <- df_US %>% mutate(hawkish = case_when(
  hawk >= 4 & hawk <= 5 ~ 1,
  hawk >= 1 & hawk <= 3 ~ 0
))
table(df_US$hawk)

df_CN <- df_CN %>% mutate(hawkish = case_when(
  hawk >= 4 & hawk <= 5 ~ 1,
  hawk >= 1 & hawk <= 3 ~ 0
))

## Nationalist (= 1)
table(df_US$natbetter)
df_US <- df_US %>%  
  mutate(nationalist = case_when(
    natbetter >= 4 & natbetter <= 5 ~ 1,
    natbetter >= 1 & natbetter <= 3 ~ 0
))
table(df_US$nationalist)

table(df_CN$natbetter)
table(df_CN$natbetter0)
df_CN <- df_CN %>% 
  mutate(nationalist = case_when(
    natbetter >= 4 & natbetter <= 5 ~ 1,
    natbetter0 >= 4 & natbetter0 <= 5 ~ 1,
    natbetter >= 1 & natbetter <= 3 ~ 0,
    natbetter0 >= 1 & natbetter0 <= 3 ~ 0
  ))
table(df_CN$nationalist)

## Chauvinist (= 1)
table(df_US$natwrong)
df_US <- df_US %>% 
  mutate(chauvinist = case_when(
    natwrong >= 4 & natwrong <= 5 ~ 1,
    natwrong >= 1 & natwrong <= 3 ~ 0
  ))
table(df_US$chauvinist)

table(df_CN$natwrong)
df_CN <- df_CN %>% 
  mutate(chauvinist = case_when(
    natwrong == 4 | natwrong == 5 ~ 1,
    natwrong == 7 | natwrong == 2 | natwrong == 3 ~ 0
  ))
table(df_CN$chauvinist)

## Risk-taker (= 1)
table(df_US$risk_1)
df_US <- df_US %>%
  mutate(risktaker = case_when(
    risk_1 >= 6 & risk_1 <= 10 ~ 1,
    risk_1 >= 0 & risk_1 <= 5 ~ 0
  ))
table(df_US$risktaker)

table(df_CN$risk_1)
df_CN <- df_CN %>%
  mutate(risktaker = case_when(
    risk_1 >= 6 & risk_1 <= 10 ~ 1,
    risk_1 >= 0 & risk_1 <= 5 ~ 0
  ))
table(df_CN$risktaker)

## Democrat, Republican, or Independent
df_US <- df_US %>% 
  mutate(partisanship = case_when(
    pid1 == 1 | pid_i == 2 ~ "Democrat",
    pid1 == 2 | pid_i == 1 ~ "Republican",
    pid_i == 3 ~ "Independent"
  ))
table(df_US$partisanship)

## CCP member (= 1)
table(df_CN$party)
df_CN <- df_CN %>% 
  mutate(ccp_member = case_when(
    party == 1 ~ 1,
    party >= 2 & party <= 4 ~ 0
  ))
table(df_CN$ccp_member)

## Income
table(df_US$income)
df_US <- df_US %>% 
  mutate(income_over_50k = case_when(
    income >= 1 & income <= 7  ~ 0,
    income >= 8 & income <= 17 ~ 1
  ))
table(df_US$income_over_50k)

table(df_CN$income1)
df_CN <- df_CN %>% 
  mutate(income_over_50k = case_when(
    income1 >= 0  & income1 <= 9  ~ 0,
    income1 >= 10 & income1 <= 19 ~ 1
  ))
table(df_CN$income_over_50k)

## Education
table(df_US$edu)
df_US <- df_US %>% 
  mutate(college = case_when(
    edu >= 5 & edu <= 8 ~ 1,
    edu >= 1 & edu <= 4 ~ 0
  ))
table(df_US$college)

table(df_CN$edu1)
df_CN <- df_CN %>% 
  mutate(college = case_when(
    edu1 == 6 & edu2 == 2 ~ 1,
    edu1 == 7 | edu1 == 8 ~ 1,
    edu1 >= 1 & edu1 <= 5 ~ 0,
    edu1 == 6 & edu2 != 2 ~ 0
  ))
table(df_CN$college)

## Political knowledge
df_US$know1 <- ifelse(df_US$know1 == 3, 1, 0)
df_US$know2 <- ifelse(df_US$know2 == 4, 1, 0)
df_US$know3 <- ifelse(df_US$know3 == 4, 1, 0)
df_US$know4 <- ifelse(df_US$know4 == 2, 1, 0)
df_US$poli_know <- df_US$know1 + df_US$know2 + df_US$know3 + df_US$know4
table(df_US$poli_know)
df_US <- df_US %>% 
  mutate(knowledgeable = case_when(
    poli_know >= 3 ~ 1,
    poli_know <= 2 ~ 0
  ))
table(df_US$knowledgeable)

df_CN$know1 <- ifelse(df_CN$know1 == 2, 1, 0)
df_CN$know2 <- ifelse(df_CN$know2 == 1, 1, 0)
df_CN$know3 <- ifelse(df_CN$know3 == 3, 1, 0)
df_CN$know4 <- ifelse(df_CN$know4 == 3, 1, 0)
df_CN$poli_know <- df_CN$know1 + df_CN$know2 + df_CN$know3 + df_CN$know4
table(df_CN$poli_know)
df_CN <- df_CN %>% 
  mutate(knowledgeable = case_when(
    poli_know == 4 ~ 1,
    poli_know <= 3 ~ 0
  ))
table(df_CN$knowledgeable)

### Figure A1: public approval across experimental conditions, seven-point variable ----
## Create an empty data frame to store the results
df_mean_approval_US <- df_mean_approval_CN <- data.frame(matrix(ncol = 5, nrow = 10))
x <- c("condition", "mean", "ci_lower", "ci_upper", "n")
colnames(df_mean_approval_US) <- colnames(df_mean_approval_CN) <- x
df_mean_approval_US$condition <- df_mean_approval_CN$condition <- 1:10

## Extract mean and CIs
for (i in 1:4) {
  # American sample
  temp_US <- lm_robust(approval ~ 1, data = df_US, subset = des == i)
  df_mean_approval_US[i + 1, 2:5] <- 
    c(temp_US$coefficients, temp_US$conf.low, temp_US$conf.high, temp_US$df + 1)
  
  # Chinese sample
  temp_CN <- lm_robust(approval ~ 1, data = df_CN, subset = des == i)
  df_mean_approval_CN[i + 1, 2:5] <- 
    c(temp_CN$coefficients, temp_CN$conf.low, temp_CN$conf.high, temp_CN$df + 1)
}

for (i in 5:8) {
  # American sample
  temp_US <- lm_robust(approval ~ 1, data = df_US, subset = des == i)
  df_mean_approval_US[i + 2, 2:5] <- 
    c(temp_US$coefficients, temp_US$conf.low, temp_US$conf.high, temp_US$df + 1)
  
  # Chinese sample
  temp_CN <- lm_robust(approval ~ 1, data = df_CN, subset = des == i)
  df_mean_approval_CN[i + 2, 2:5] <- 
    c(temp_CN$coefficients, temp_CN$conf.low, temp_CN$conf.high, temp_CN$df + 1)
}

## Visualize the results for the American sample
df_mean_approval_US$condition <- 
  factor(df_mean_approval_US$condition, levels = c(1:10),
         labels = c("US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs"))
df_mean_approval_US$condition <- factor(df_mean_approval_US$condition, 
                                        levels = rev(levels(df_mean_approval_US$condition)))
df_mean_approval_US$color <- factor(rep(1:5, 2))
p1 <- ggplot(df_mean_approval_US, aes(x = mean, y = condition, color = color)) +
  geom_point(size = 2) +
  geom_text(label = round(df_mean_approval_US$mean, 1), vjust = -1, size = 4, family = "Times") +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), linewidth = .7, width = 0) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 3, color = "grey50", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic"))

## Visualize the results for the Chinese sample
df_mean_approval_CN$condition <- 
  factor(df_mean_approval_CN$condition, levels = c(1:10),
         labels = c("China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs"))
df_mean_approval_CN$condition <- factor(df_mean_approval_CN$condition, 
                                        levels = rev(levels(df_mean_approval_CN$condition)))
df_mean_approval_CN$color <- factor(rep(1:5, 2))
p2 <- ggplot(df_mean_approval_CN, aes(x = mean, y = condition, color = color)) +
  geom_point(size = 2) +
  geom_text(label = round(df_mean_approval_CN$mean, 1), vjust = -1, size = 4, family = "Times") +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 3, color = "grey50", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic"))

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure A1.pdf", width = 8, height = 8)

### Figure 2: public approval across experimental conditions, binary approval ----
## Create an empty data frame to store the results
df_perc_approval_US <- df_perc_approval_CN <- data.frame(matrix(ncol = 5, nrow = 10))
x <- c("condition", "percent", "ci_lower", "ci_upper", "n")
colnames(df_perc_approval_US) <- colnames(df_perc_approval_CN) <- x
df_perc_approval_US$condition <- df_mean_approval_US$condition
df_perc_approval_CN$condition <- df_mean_approval_CN$condition

## Extract proportion and CIs
for (i in 1:4) {
  # American sample
  x_US <- sum(df_US$approval_bin[df_US$des == i], na.rm = T)
  n_US <- sum(!is.na(df_US$approval_bin[df_US$des == i]))
  temp_US <- prop.test(x_US, n_US, correct = F)
  df_perc_approval_US[i + 1, 2:5] <- c(temp_US$estimate * 100, temp_US$conf.int[1:2] * 100, n_US)
  
  # Chinese sample
  x_CN <- sum(df_CN$approval_bin[df_CN$des == i], na.rm = T)
  n_CN <- sum(!is.na(df_CN$approval_bin[df_CN$des == i]))
  temp_CN <- prop.test(x_CN, n_CN, correct = F)
  df_perc_approval_CN[i + 1, 2:5] <- c(temp_CN$estimate * 100, temp_CN$conf.int[1:2] * 100, n_CN)
}
for (i in 5:8) {
  # American sample
  x_US <- sum(df_US$approval_bin[df_US$des == i], na.rm = T)
  n_US <- sum(!is.na(df_US$approval_bin[df_US$des == i]))
  temp_US <- prop.test(x_US, n_US, correct = F)
  df_perc_approval_US[i + 2, 2:5] <- c(temp_US$estimate * 100, temp_US$conf.int[1:2] * 100, n_US)
  
  # Chinese sample
  x_CN <- sum(df_CN$approval_bin[df_CN$des == i], na.rm = T)
  n_CN <- sum(!is.na(df_CN$approval_bin[df_CN$des == i]))
  temp_CN <- prop.test(x_CN, n_CN, correct = F)
  df_perc_approval_CN[i + 2, 2:5] <- c(temp_CN$estimate * 100, temp_CN$conf.int[1:2] * 100, n_CN)
}

df_perc_approval_US$color <- factor(rep(1:5, 2))
df_perc_approval_CN$color <- factor(rep(1:5, 2))

## Visualize the results for the American sample
p1 <- ggplot(df_perc_approval_US, aes(x = percent, y = condition, color = color)) +
  geom_point(size = 2) +
  geom_text(label = round(df_perc_approval_US$percent, 0), vjust = -1, size = 4, family = "Times") +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  ylab("") +
  xlab("Percent Approved\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 100)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 50, color = "grey50", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic"))

## Visualize the results for the Chinese sample
p2 <- ggplot(df_perc_approval_CN, aes(x = percent, y = condition, color = color)) +
  geom_point(size = 2) +
  geom_text(label = round(df_perc_approval_CN$percent, 0), vjust = -1, size = 4, family = "Times") +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  ylab("") +
  xlab("Percent Approved\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 100)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 50, color = "grey50", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic"))

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure 2.pdf", width = 8, height = 8)
ggsave(file = "Figure 2.jpg", width = 8, height = 8, dpi = 1200)

## Hypothesis testing
# Balanced reciprocity vs. no reciprocity (first mover = China)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 6], na.rm = T), sum(df_US$approval_bin[df_US$des == 8], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 6])), sum(!is.na(df_US$approval_bin[df_US$des == 8]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 2], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 4], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 2])), sum(!is.na(df_CN$approval_bin[df_CN$des == 4]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Balanced reciprocity vs. no reciprocity (first mover = the US)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 2], na.rm = T), sum(df_US$approval_bin[df_US$des == 4], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 2])), sum(!is.na(df_US$approval_bin[df_US$des == 4]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 6], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 8], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 6])), sum(!is.na(df_CN$approval_bin[df_CN$des == 8]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Super-reciprocity vs. balanced reciprocity (first mover = the US)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 1], na.rm = T), sum(df_US$approval_bin[df_US$des == 2], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 1])), sum(!is.na(df_US$approval_bin[df_US$des == 2]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 5], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 6], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 5])), sum(!is.na(df_CN$approval_bin[df_CN$des == 6]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Super-reciprocity vs. balanced reciprocity (first mover = China)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 5], na.rm = T), sum(df_US$approval_bin[df_US$des == 6], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 5])), sum(!is.na(df_US$approval_bin[df_US$des == 6]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 1], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 2], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 1])), sum(!is.na(df_CN$approval_bin[df_CN$des == 2]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Semi-reciprocity vs. balanced reciprocity (first mover = the US)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 3], na.rm = T), sum(df_US$approval_bin[df_US$des == 2], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 3])), sum(!is.na(df_US$approval_bin[df_US$des == 2]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 7], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 6], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 7])), sum(!is.na(df_CN$approval_bin[df_CN$des == 6]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Semi-reciprocity vs. balanced reciprocity (first mover = China)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 7], na.rm = T), sum(df_US$approval_bin[df_US$des == 6], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 7])), sum(!is.na(df_US$approval_bin[df_US$des == 6]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 3], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 2], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 3])), sum(!is.na(df_CN$approval_bin[df_CN$des == 2]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Super-reciprocity vs. no reciprocity (first mover = the US)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 1], na.rm = T), sum(df_US$approval_bin[df_US$des == 4], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 1])), sum(!is.na(df_US$approval_bin[df_US$des == 4]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 5], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 8], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 5])), sum(!is.na(df_CN$approval_bin[df_CN$des == 8]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Super-reciprocity vs. no reciprocity (first mover = China)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 5], na.rm = T), sum(df_US$approval_bin[df_US$des == 8], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 5])), sum(!is.na(df_US$approval_bin[df_US$des == 8]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 1], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 4], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 1])), sum(!is.na(df_CN$approval_bin[df_CN$des == 4]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Semi-reciprocity vs. no reciprocity (first mover = the US)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 3], na.rm = T), sum(df_US$approval_bin[df_US$des == 4], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 3])), sum(!is.na(df_US$approval_bin[df_US$des == 4]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 7], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 8], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 7])), sum(!is.na(df_CN$approval_bin[df_CN$des == 8]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

# Semi-reciprocity vs. no reciprocity (first mover = China)
prop.test(x = c(sum(df_US$approval_bin[df_US$des == 7], na.rm = T), sum(df_US$approval_bin[df_US$des == 8], na.rm = T)),
          n = c(sum(!is.na(df_US$approval_bin[df_US$des == 7])), sum(!is.na(df_US$approval_bin[df_US$des == 8]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)
prop.test(x = c(sum(df_CN$approval_bin[df_CN$des == 3], na.rm = T), sum(df_CN$approval_bin[df_CN$des == 4], na.rm = T)),
          n = c(sum(!is.na(df_CN$approval_bin[df_CN$des == 3])), sum(!is.na(df_CN$approval_bin[df_CN$des == 4]))),
          alternative = c("two.sided"), conf.level = 0.95, correct = FALSE)

### Figure 3: public approval across experimental conditions, by nationalism ----
## Create an empty data frame to store the results
df_mean_approval_US_nat <- df_mean_approval_CN_nat <- data.frame(matrix(ncol = 6, nrow = 18))
x <- c("condition", "mean", "ci_lower", "ci_upper", "n", "nationalist")
colnames(df_mean_approval_US_nat) <- colnames(df_mean_approval_CN_nat) <- x
df_mean_approval_US_nat$condition <- df_mean_approval_CN_nat$condition <- 1:18

## Extract mean and CIs
for (i in 1:4) {
  # American sample
  temp_US_nat <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (nationalist == 1))
  df_mean_approval_US_nat[i + 1, 2:5] <- 
    c(temp_US_nat$coefficients, temp_US_nat$conf.low, temp_US_nat$conf.high, temp_US_nat$df + 1)
  df_mean_approval_US_nat[i + 1, 6] <- "Nationalist"
  temp_US_nonnat <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (nationalist == 0))
  df_mean_approval_US_nat[i + 5, 2:5] <- 
    c(temp_US_nonnat$coefficients, temp_US_nonnat$conf.low, temp_US_nonnat$conf.high, temp_US_nonnat$df + 1)
  df_mean_approval_US_nat[i + 5, 6] <- "Non-Nationalist"
  
  # Chinese sample
  temp_CN_nat <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (nationalist == 1))
  df_mean_approval_CN_nat[i + 1, 2:5] <- 
    c(temp_CN_nat$coefficients, temp_CN_nat$conf.low, temp_CN_nat$conf.high, temp_CN_nat$df + 1)
  df_mean_approval_CN_nat[i + 1, 6] <- "Nationalist"
  temp_CN_nonnat <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (nationalist == 0))
  df_mean_approval_CN_nat[i + 5, 2:5] <- 
    c(temp_CN_nonnat$coefficients, temp_CN_nonnat$conf.low, temp_CN_nonnat$conf.high, temp_CN_nonnat$df + 1)
  df_mean_approval_CN_nat[i + 5, 6] <- "Non-Nationalist"
}
for (i in 5:8) {
  # American sample
  temp_US_nat <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (nationalist == 1))
  df_mean_approval_US_nat[i + 6, 2:5] <- 
    c(temp_US_nat$coefficients, temp_US_nat$conf.low, temp_US_nat$conf.high, temp_US_nat$df + 1)
  df_mean_approval_US_nat[i + 6, 6] <- "Nationalist"
  temp_US_nonnat <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (nationalist == 0))
  df_mean_approval_US_nat[i + 10, 2:5] <- 
    c(temp_US_nonnat$coefficients, temp_US_nonnat$conf.low, temp_US_nonnat$conf.high, temp_US_nonnat$df + 1)
  df_mean_approval_US_nat[i + 10, 6] <- "Non-Nationalist"
  
  # Chinese sample
  temp_CN_nat <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (nationalist == 1))
  df_mean_approval_CN_nat[i + 6, 2:5] <- 
    c(temp_CN_nat$coefficients, temp_CN_nat$conf.low, temp_CN_nat$conf.high, temp_CN_nat$df + 1)
  df_mean_approval_CN_nat[i + 6, 6] <- "Nationalist"
  temp_CN_nonnat <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (nationalist == 0))
  df_mean_approval_CN_nat[i + 10, 2:5] <- 
    c(temp_CN_nonnat$coefficients, temp_CN_nonnat$conf.low, temp_CN_nonnat$conf.high, temp_CN_nonnat$df + 1)
  df_mean_approval_CN_nat[i + 10, 6] <- "Non-Nationalist"
}

## Visualize the results for the American sample
df_mean_approval_US_nat$condition <- 
  factor(df_mean_approval_US_nat$condition, levels = c(1:18),
         labels = c("US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs"))
df_mean_approval_US_nat$condition <- factor(df_mean_approval_US_nat$condition, 
                                            levels = rev(levels(df_mean_approval_US_nat$condition)))
df_mean_approval_US_nat$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p1 <- ggplot(df_mean_approval_US_nat, aes(x = mean, y = condition, color = color, 
                                          shape = nationalist, linetype = nationalist)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 3, color = "grey50", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p1 <- p1 + 
  annotate("text", x = 1.66, y = 1.15, label = "non-nationalist", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 4.85, y = 0.9, label = "nationalist", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Visualize the results for the Chinese sample
df_mean_approval_CN_nat$condition <- 
  factor(df_mean_approval_CN_nat$condition, levels = c(1:18),
         labels = c("China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs"))
df_mean_approval_CN_nat$condition <- factor(df_mean_approval_CN_nat$condition, 
                                            levels = rev(levels(df_mean_approval_CN_nat$condition)))
df_mean_approval_CN_nat$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p2 <- ggplot(df_mean_approval_CN_nat, aes(x = mean, y = condition, color = color, 
                                          shape = nationalist, linetype = nationalist)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 3, color = "grey50", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p2 <- p2 + 
  annotate("text", x = 2.49, y = 1.15, label = "non-nationalist", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 5.52, y = 0.9, label = "nationalist", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure 3.pdf", width = 8, height = 8)
ggsave(file = "Figure 3.jpg", width = 8, height = 8, dpi = 1200)

### Figure A2: public approval across experimental conditions, by risk preference ----
## Create an empty data frame to store the results
df_mean_approval_US_risk <- df_mean_approval_CN_risk <- data.frame(matrix(ncol = 6, nrow = 18))
x <- c("condition", "mean", "ci_lower", "ci_upper", "n", "risktaker")
colnames(df_mean_approval_US_risk) <- colnames(df_mean_approval_CN_risk) <- x
df_mean_approval_US_risk$condition <- df_mean_approval_CN_risk$condition <- 1:18

## Extract mean and CIs
for (i in 1:4) {
  # American sample
  temp_US_risk <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (risktaker == 1))
  df_mean_approval_US_risk[i + 1, 2:5] <- 
    c(temp_US_risk$coefficients, temp_US_risk$conf.low, temp_US_risk$conf.high, temp_US_risk$df + 1)
  df_mean_approval_US_risk[i + 1, 6] <- "Risktaker"
  temp_US_nonrisk <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (risktaker == 0))
  df_mean_approval_US_risk[i + 5, 2:5] <- 
    c(temp_US_nonrisk$coefficients, temp_US_nonrisk$conf.low, temp_US_nonrisk$conf.high, temp_US_nonrisk$df + 1)
  df_mean_approval_US_risk[i + 5, 6] <- "Non-Risktaker"
  
  # Chinese sample
  temp_CN_risk <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (risktaker == 1))
  df_mean_approval_CN_risk[i + 1, 2:5] <- 
    c(temp_CN_risk$coefficients, temp_CN_risk$conf.low, temp_CN_risk$conf.high, temp_CN_risk$df + 1)
  df_mean_approval_CN_risk[i + 1, 6] <- "Risktaker"
  temp_CN_nonrisk <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (risktaker == 0))
  df_mean_approval_CN_risk[i + 5, 2:5] <- 
    c(temp_CN_nonrisk$coefficients, temp_CN_nonrisk$conf.low, temp_CN_nonrisk$conf.high, temp_CN_nonrisk$df + 1)
  df_mean_approval_CN_risk[i + 5, 6] <- "Non-Risktaker"
}

for (i in 5:8) {
  # American sample
  temp_US_risk <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (risktaker == 1))
  df_mean_approval_US_risk[i + 6, 2:5] <- 
    c(temp_US_risk$coefficients, temp_US_risk$conf.low, temp_US_risk$conf.high, temp_US_risk$df + 1)
  df_mean_approval_US_risk[i + 6, 6] <- "Risktaker"
  temp_US_nonrisk <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (risktaker == 0))
  df_mean_approval_US_risk[i + 10, 2:5] <- 
    c(temp_US_nonrisk$coefficients, temp_US_nonrisk$conf.low, temp_US_nonrisk$conf.high, temp_US_nonrisk$df + 1)
  df_mean_approval_US_risk[i + 10, 6] <- "Non-Risktaker"
  
  # Chinese sample
  temp_CN_risk <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (risktaker == 1))
  df_mean_approval_CN_risk[i + 6, 2:5] <- 
    c(temp_CN_risk$coefficients, temp_CN_risk$conf.low, temp_CN_risk$conf.high, temp_CN_risk$df + 1)
  df_mean_approval_CN_risk[i + 6, 6] <- "Risktaker"
  temp_CN_nonrisk <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (risktaker == 0))
  df_mean_approval_CN_risk[i + 10, 2:5] <- 
    c(temp_CN_nonrisk$coefficients, temp_CN_nonrisk$conf.low, temp_CN_nonrisk$conf.high, temp_CN_nonrisk$df + 1)
  df_mean_approval_CN_risk[i + 10, 6] <- "Non-Risktaker"
}

## Visualize the results for the American sample
df_mean_approval_US_risk$condition <- 
  factor(df_mean_approval_US_risk$condition, levels = c(1:18),
         labels = c("US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs"))
df_mean_approval_US_risk$condition <- factor(df_mean_approval_US_risk$condition, 
                                             levels = rev(levels(df_mean_approval_US_risk$condition)))
df_mean_approval_US_risk$color <- factor(rep(c(0, rep(1:4, 2)), 2))
df_mean_approval_US_risk$risktaker <- factor(df_mean_approval_US_risk$risktaker,
                                             levels = c("Risktaker", "Non-Risktaker"))
p1 <- ggplot(df_mean_approval_US_risk, aes(x = mean, y = condition, color = color, 
                                           shape = risktaker, linetype = risktaker)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 3, color = "grey50", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p1 <- p1 + 
  annotate("text", x = 2.00, y = 1.15, label = "non-risktaker", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 4.50, y = 0.9, label = "risktaker", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Visualize the results for the Chinese sample
df_mean_approval_CN_risk$condition <- 
  factor(df_mean_approval_CN_risk$condition, levels = c(1:18),
         labels = c("China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs"))
df_mean_approval_CN_risk$condition <- factor(df_mean_approval_CN_risk$condition, 
                                             levels = rev(levels(df_mean_approval_CN_risk$condition)))
df_mean_approval_CN_risk$color <- factor(rep(c(0, rep(1:4, 2)), 2))
df_mean_approval_CN_risk$risktaker <- factor(df_mean_approval_CN_risk$risktaker,
                                             levels = c("Risktaker", "Non-Risktaker"))
p2 <- ggplot(df_mean_approval_CN_risk, aes(x = mean, y = condition, color = color, 
                                           shape = risktaker, linetype = risktaker)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 3, color = "grey50", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p2 <- p2 + 
  annotate("text", x = 3.28, y = 1.15, label = "non-risktaker", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 5.48, y = 0.9, label = "risktaker", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure A2.pdf", width = 8, height = 8)

### Figure A3: public approval across experimental conditions, by chauvinism ----
## Create an empty data frame to store the results
df_mean_approval_US_chau <- df_mean_approval_CN_chau <- data.frame(matrix(ncol = 6, nrow = 18))
x <- c("condition", "mean", "ci_lower", "ci_upper", "n", "chauvinist")
colnames(df_mean_approval_US_chau) <- colnames(df_mean_approval_CN_chau) <- x
df_mean_approval_US_chau$condition <- df_mean_approval_CN_chau$condition <- 1:18

## Extract mean and CIs
for (i in 1:4) {
  # American sample
  temp_US_chau <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (chauvinist == 1))
  df_mean_approval_US_chau[i + 1, 2:5] <- 
    c(temp_US_chau$coefficients, temp_US_chau$conf.low, temp_US_chau$conf.high, temp_US_chau$df + 1)
  df_mean_approval_US_chau[i + 1, 6] <- "Chauvinist"
  temp_US_nonchau <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (chauvinist == 0))
  df_mean_approval_US_chau[i + 5, 2:5] <- 
    c(temp_US_nonchau$coefficients, temp_US_nonchau$conf.low, temp_US_nonchau$conf.high, temp_US_nonchau$df + 1)
  df_mean_approval_US_chau[i + 5, 6] <- "Non-Chauvinist"
  
  # Chinese sample
  temp_CN_chau <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (chauvinist == 1))
  df_mean_approval_CN_chau[i + 1, 2:5] <- 
    c(temp_CN_chau$coefficients, temp_CN_chau$conf.low, temp_CN_chau$conf.high, temp_CN_chau$df + 1)
  df_mean_approval_CN_chau[i + 1, 6] <- "Chauvinist"
  temp_CN_nonchau <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (chauvinist == 0))
  df_mean_approval_CN_chau[i + 5, 2:5] <- 
    c(temp_CN_nonchau$coefficients, temp_CN_nonchau$conf.low, temp_CN_nonchau$conf.high, temp_CN_nonchau$df + 1)
  df_mean_approval_CN_chau[i + 5, 6] <- "Non-Chauvinist"
}

for (i in 5:8) {
  # American sample
  temp_US_chau <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (chauvinist == 1))
  df_mean_approval_US_chau[i + 6, 2:5] <- 
    c(temp_US_chau$coefficients, temp_US_chau$conf.low, temp_US_chau$conf.high, temp_US_chau$df + 1)
  df_mean_approval_US_chau[i + 6, 6] <- "Chauvinist"
  temp_US_nonchau <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (chauvinist == 0))
  df_mean_approval_US_chau[i + 10, 2:5] <- 
    c(temp_US_nonchau$coefficients, temp_US_nonchau$conf.low, temp_US_nonchau$conf.high, temp_US_nonchau$df + 1)
  df_mean_approval_US_chau[i + 10, 6] <- "Non-Chauvinist"
  
  # Chinese sample
  temp_CN_chau <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (chauvinist == 1))
  df_mean_approval_CN_chau[i + 6, 2:5] <- 
    c(temp_CN_chau$coefficients, temp_CN_chau$conf.low, temp_CN_chau$conf.high, temp_CN_chau$df + 1)
  df_mean_approval_CN_chau[i + 6, 6] <- "Chauvinist"
  temp_CN_nonchau <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (chauvinist == 0))
  df_mean_approval_CN_chau[i + 10, 2:5] <- 
    c(temp_CN_nonchau$coefficients, temp_CN_nonchau$conf.low, temp_CN_nonchau$conf.high, temp_CN_nonchau$df + 1)
  df_mean_approval_CN_chau[i + 10, 6] <- "Non-Chauvinist"
}

## Visualize the results for the American sample
df_mean_approval_US_chau$condition <- 
  factor(df_mean_approval_US_chau$condition, levels = c(1:18),
         labels = c("US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs"))
df_mean_approval_US_chau$condition <- factor(df_mean_approval_US_chau$condition, 
                                             levels = rev(levels(df_mean_approval_US_chau$condition)))
df_mean_approval_US_chau$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p1 <- ggplot(df_mean_approval_US_chau, aes(x = mean, y = condition, color = color, 
                                           shape = chauvinist, linetype = chauvinist)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p1 <- p1 + 
  annotate("text", x = 1.90, y = 1.15, label = "non-chauvinist", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 5.10, y = 0.9, label = "chauvinist", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Visualize the results for the Chinese sample
df_mean_approval_CN_chau$condition <- 
  factor(df_mean_approval_CN_chau$condition, levels = c(1:18),
         labels = c("China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs"))
df_mean_approval_CN_chau$condition <- factor(df_mean_approval_CN_chau$condition, 
                                             levels = rev(levels(df_mean_approval_CN_chau$condition)))
df_mean_approval_CN_chau$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p2 <- ggplot(df_mean_approval_CN_chau, aes(x = mean, y = condition, color = color, 
                                           shape = chauvinist, linetype = chauvinist)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p2 <- p2 + 
  annotate("text", x = 2.60, y = 1.15, label = "non-chauvinist", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 5.50, y = 0.9, label = "chauvinist", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure A3.pdf", width = 8, height = 8)

### Figure A4: public approval across experimental conditions, by political knowledge ----
## Create an empty data frame to store the results
df_mean_approval_US_know <- df_mean_approval_CN_know <- data.frame(matrix(ncol = 6, nrow = 18))
x <- c("condition", "mean", "ci_lower", "ci_upper", "n", "poli_know")
colnames(df_mean_approval_US_know) <- colnames(df_mean_approval_CN_know) <- x
df_mean_approval_US_know$condition <- df_mean_approval_CN_know$condition <- 1:18

## Extract mean and CIs
for (i in 1:4) {
  # American sample
  temp_US_know <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (knowledgeable == 1))
  df_mean_approval_US_know[i + 1, 2:5] <- 
    c(temp_US_know$coefficients, temp_US_know$conf.low, temp_US_know$conf.high, temp_US_know$df + 1)
  df_mean_approval_US_know[i + 1, 6] <- "High Knowledge"
  temp_US_lessknow <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (knowledgeable == 0))
  df_mean_approval_US_know[i + 5, 2:5] <- 
    c(temp_US_lessknow$coefficients, temp_US_lessknow$conf.low, temp_US_lessknow$conf.high, temp_US_lessknow$df + 1)
  df_mean_approval_US_know[i + 5, 6] <- "Low Knowledge"
  
  # Chinese sample
  temp_CN_know <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (knowledgeable == 1))
  df_mean_approval_CN_know[i + 1, 2:5] <- 
    c(temp_CN_know$coefficients, temp_CN_know$conf.low, temp_CN_know$conf.high, temp_CN_know$df + 1)
  df_mean_approval_CN_know[i + 1, 6] <- "High Knowledge"
  temp_CN_lessknow <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (knowledgeable == 0))
  df_mean_approval_CN_know[i + 5, 2:5] <- 
    c(temp_CN_lessknow$coefficients, temp_CN_lessknow$conf.low, temp_CN_lessknow$conf.high, temp_CN_lessknow$df + 1)
  df_mean_approval_CN_know[i + 5, 6] <- "Low Knowledge"
}

for (i in 5:8) {
  # American sample
  temp_US_know <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (knowledgeable == 1))
  df_mean_approval_US_know[i + 6, 2:5] <- 
    c(temp_US_know$coefficients, temp_US_know$conf.low, temp_US_know$conf.high, temp_US_know$df + 1)
  df_mean_approval_US_know[i + 6, 6] <- "High Knowledge"
  temp_US_lessknow <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (knowledgeable == 0))
  df_mean_approval_US_know[i + 10, 2:5] <- 
    c(temp_US_lessknow$coefficients, temp_US_lessknow$conf.low, temp_US_lessknow$conf.high, temp_US_lessknow$df + 1)
  df_mean_approval_US_know[i + 10, 6] <- "Low Knowledge"
  
  # Chinese sample
  temp_CN_know <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (knowledgeable == 1))
  df_mean_approval_CN_know[i + 6, 2:5] <- 
    c(temp_CN_know$coefficients, temp_CN_know$conf.low, temp_CN_know$conf.high, temp_CN_know$df + 1)
  df_mean_approval_CN_know[i + 6, 6] <- "High Knowledge"
  temp_CN_lessknow <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (knowledgeable == 0))
  df_mean_approval_CN_know[i + 10, 2:5] <- 
    c(temp_CN_lessknow$coefficients, temp_CN_lessknow$conf.low, temp_CN_lessknow$conf.high, temp_CN_lessknow$df + 1)
  df_mean_approval_CN_know[i + 10, 6] <- "Low Knowledge"
}

## Visualize the results for the American sample
df_mean_approval_US_know$condition <- 
  factor(df_mean_approval_US_know$condition, levels = c(1:18),
         labels = c("US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs"))
df_mean_approval_US_know$condition <- factor(df_mean_approval_US_know$condition, 
                                             levels = rev(levels(df_mean_approval_US_know$condition)))
df_mean_approval_US_know$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p1 <- ggplot(df_mean_approval_US_know, aes(x = mean, y = condition, color = color, 
                                           shape = poli_know, linetype = poli_know)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p1 <- p1 + 
  annotate("text", x = 2.30, y = 1.15, label = "low knowledge", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 4.45, y = 0.9, label = "high knowledge", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Visualize the results for the Chinese sample
df_mean_approval_CN_know$condition <- 
  factor(df_mean_approval_CN_know$condition, levels = c(1:18),
         labels = c("China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs"))
df_mean_approval_CN_know$condition <- factor(df_mean_approval_CN_know$condition, 
                                             levels = rev(levels(df_mean_approval_CN_know$condition)))
df_mean_approval_CN_know$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p2 <- ggplot(df_mean_approval_CN_know, aes(x = mean, y = condition, color = color, 
                                           shape = poli_know, linetype = poli_know)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p2 <- p2 + 
  annotate("text", x = 3.60, y = 1.15, label = "low knowledge", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 5.45, y = 0.9, label = "high knowledge", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure A4.pdf", width = 8, height = 8)

### Figure A5: public approval across experimental conditions, by college education ----
## Create an empty data frame to store the results
df_mean_approval_US_edu <- df_mean_approval_CN_edu <- data.frame(matrix(ncol = 6, nrow = 18))
x <- c("condition", "mean", "ci_lower", "ci_upper", "n", "education")
colnames(df_mean_approval_US_edu) <- colnames(df_mean_approval_CN_edu) <- x
df_mean_approval_US_edu$condition <- df_mean_approval_CN_edu$condition <- 1:18

## Extract mean and CIs
for (i in 1:4) {
  # American sample
  temp_US_edu <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (college == 1))
  df_mean_approval_US_edu[i + 1, 2:5] <- 
    c(temp_US_edu$coefficients, temp_US_edu$conf.low, temp_US_edu$conf.high, temp_US_edu$df + 1)
  df_mean_approval_US_edu[i + 1, 6] <- "College Graduate"
  temp_US_lessedu <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (college == 0))
  df_mean_approval_US_edu[i + 5, 2:5] <- 
    c(temp_US_lessedu$coefficients, temp_US_lessedu$conf.low, temp_US_lessedu$conf.high, temp_US_lessedu$df + 1)
  df_mean_approval_US_edu[i + 5, 6] <- "Non-College Graduate"
  
  # Chinese sample
  temp_CN_edu <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (college == 1))
  df_mean_approval_CN_edu[i + 1, 2:5] <- 
    c(temp_CN_edu$coefficients, temp_CN_edu$conf.low, temp_CN_edu$conf.high, temp_CN_edu$df + 1)
  df_mean_approval_CN_edu[i + 1, 6] <- "College Graduate"
  temp_CN_lessedu <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (college == 0))
  df_mean_approval_CN_edu[i + 5, 2:5] <- 
    c(temp_CN_lessedu$coefficients, temp_CN_lessedu$conf.low, temp_CN_lessedu$conf.high, temp_CN_lessedu$df + 1)
  df_mean_approval_CN_edu[i + 5, 6] <- "Non-College Graduate"
}

for (i in 5:8) {
  # American sample
  temp_US_edu <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (college == 1))
  df_mean_approval_US_edu[i + 6, 2:5] <- 
    c(temp_US_edu$coefficients, temp_US_edu$conf.low, temp_US_edu$conf.high, temp_US_edu$df + 1)
  df_mean_approval_US_edu[i + 6, 6] <- "College Graduate"
  temp_US_lessedu <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (college == 0))
  df_mean_approval_US_edu[i + 10, 2:5] <- 
    c(temp_US_lessedu$coefficients, temp_US_lessedu$conf.low, temp_US_lessedu$conf.high, temp_US_lessedu$df + 1)
  df_mean_approval_US_edu[i + 10, 6] <- "Non-College Graduate"
  
  # Chinese sample
  temp_CN_edu <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (college == 1))
  df_mean_approval_CN_edu[i + 6, 2:5] <- 
    c(temp_CN_edu$coefficients, temp_CN_edu$conf.low, temp_CN_edu$conf.high, temp_CN_edu$df + 1)
  df_mean_approval_CN_edu[i + 6, 6] <- "College Graduate"
  temp_CN_lessedu <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (college == 0))
  df_mean_approval_CN_edu[i + 10, 2:5] <- 
    c(temp_CN_lessedu$coefficients, temp_CN_lessedu$conf.low, temp_CN_lessedu$conf.high, temp_CN_lessedu$df + 1)
  df_mean_approval_CN_edu[i + 10, 6] <- "Non-College Graduate"
}

## Visualize the results for the American sample
df_mean_approval_US_edu$condition <- 
  factor(df_mean_approval_US_edu$condition, levels = c(1:18),
         labels = c("US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs"))
df_mean_approval_US_edu$condition <- factor(df_mean_approval_US_edu$condition, 
                                            levels = rev(levels(df_mean_approval_US_edu$condition)))
df_mean_approval_US_edu$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p1 <- ggplot(df_mean_approval_US_edu, aes(x = mean, y = condition, color = color, 
                                          shape = education, linetype = education)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p1 <- p1 + 
  annotate("text", x = 2.00, y = 1.15, label = "non-college educated", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 4.65, y = 0.9, label = "college educated", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Visualize the results for the Chinese sample
df_mean_approval_CN_edu$condition <- 
  factor(df_mean_approval_CN_edu$condition, levels = c(1:18),
         labels = c("China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs"))
df_mean_approval_CN_edu$condition <- factor(df_mean_approval_CN_edu$condition, 
                                            levels = rev(levels(df_mean_approval_CN_edu$condition)))
df_mean_approval_CN_edu$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p2 <- ggplot(df_mean_approval_CN_edu, aes(x = mean, y = condition, color = color, 
                                          shape = education, linetype = education)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p2 <- p2 + 
  annotate("text", x = 3.20, y = 1.15, label = "non-college educated", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 5.65, y = 0.9, label = "college educated", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure A5.pdf", width = 8, height = 8)

### Figure A6: public approval across experimental conditions, by partisanship ----
## Create an empty data frame to store the results
df_mean_approval_US_pid <- df_mean_approval_CN_pid <- data.frame(matrix(ncol = 6, nrow = 18))
x <- c("condition", "mean", "ci_lower", "ci_upper", "n", "pid")
colnames(df_mean_approval_US_pid) <- colnames(df_mean_approval_CN_pid) <- x
df_mean_approval_US_pid$condition <- df_mean_approval_CN_pid$condition <- 1:18

## Extract mean and CIs
for (i in 1:4) {
  # American sample
  temp_US_pid <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (partisanship == "Republican"))
  df_mean_approval_US_pid[i + 1, 2:5] <- 
    c(temp_US_pid$coefficients, temp_US_pid$conf.low, temp_US_pid$conf.high, temp_US_pid$df + 1)
  df_mean_approval_US_pid[i + 1, 6] <- "Republican"
  temp_US_pid2 <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (partisanship == "Democrat"))
  df_mean_approval_US_pid[i + 5, 2:5] <- 
    c(temp_US_pid2$coefficients, temp_US_pid2$conf.low, temp_US_pid2$conf.high, temp_US_pid2$df + 1)
  df_mean_approval_US_pid[i + 5, 6] <- "Democrat"
  
  # Chinese sample
  temp_CN_pid <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (ccp_member == 1))
  df_mean_approval_CN_pid[i + 1, 2:5] <- 
    c(temp_CN_pid$coefficients, temp_CN_pid$conf.low, temp_CN_pid$conf.high, temp_CN_pid$df + 1)
  df_mean_approval_CN_pid[i + 1, 6] <- "CCP Member"
  temp_CN_pid2 <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (ccp_member == 0))
  df_mean_approval_CN_pid[i + 5, 2:5] <- 
    c(temp_CN_pid2$coefficients, temp_CN_pid2$conf.low, temp_CN_pid2$conf.high, temp_CN_pid2$df + 1)
  df_mean_approval_CN_pid[i + 5, 6] <- "Non-CCP Member"
}

for (i in 5:8) {
  # American sample
  temp_US_pid <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (partisanship == "Republican"))
  df_mean_approval_US_pid[i + 6, 2:5] <- 
    c(temp_US_pid$coefficients, temp_US_pid$conf.low, temp_US_pid$conf.high, temp_US_pid$df + 1)
  df_mean_approval_US_pid[i + 6, 6] <- "Republican"
  temp_US_pid2 <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (partisanship == "Democrat"))
  df_mean_approval_US_pid[i + 10, 2:5] <- 
    c(temp_US_pid2$coefficients, temp_US_pid2$conf.low, temp_US_pid2$conf.high, temp_US_pid2$df + 1)
  df_mean_approval_US_pid[i + 10, 6] <- "Democrat"
  
  # Chinese sample
  temp_CN_pid <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (ccp_member == 1))
  df_mean_approval_CN_pid[i + 6, 2:5] <- 
    c(temp_CN_pid$coefficients, temp_CN_pid$conf.low, temp_CN_pid$conf.high, temp_CN_pid$df + 1)
  df_mean_approval_CN_pid[i + 6, 6] <- "CCP Member"
  temp_CN_pid2 <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (ccp_member == 0))
  df_mean_approval_CN_pid[i + 10, 2:5] <- 
    c(temp_CN_pid2$coefficients, temp_CN_pid2$conf.low, temp_CN_pid2$conf.high, temp_CN_pid2$df + 1)
  df_mean_approval_CN_pid[i + 10, 6] <- "Non-CCP Member"
}

## Visualize the results for the American sample
df_mean_approval_US_pid$condition <- 
  factor(df_mean_approval_US_pid$condition, levels = c(1:18),
         labels = c("US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs"))
df_mean_approval_US_pid$condition <- factor(df_mean_approval_US_pid$condition, 
                                            levels = rev(levels(df_mean_approval_US_pid$condition)))
df_mean_approval_US_pid$color <- factor(rep(c(0, rep(1:4, 2)), 2))
df_mean_approval_US_pid$pid <- factor(df_mean_approval_US_pid$pid,
                                      levels = c("Republican", "Democrat"))
p1 <- ggplot(df_mean_approval_US_pid, aes(x = mean, y = condition, color = color, 
                                          shape = pid, linetype = pid)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p1 <- p1 + 
  annotate("text", x = 4.35, y = 1.15, label = "Democrat", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 1.95, y = 0.9, label = "Republican", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Visualize the results for the Chinese sample
df_mean_approval_CN_pid$condition <- 
  factor(df_mean_approval_CN_pid$condition, levels = c(1:18),
         labels = c("China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs"))
df_mean_approval_CN_pid$condition <- factor(df_mean_approval_CN_pid$condition, 
                                            levels = rev(levels(df_mean_approval_CN_pid$condition)))
df_mean_approval_CN_pid$color <- factor(rep(c(0, rep(1:4, 2)), 2))
p2 <- ggplot(df_mean_approval_CN_pid, aes(x = mean, y = condition, color = color, 
                                          shape = pid, linetype = pid)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p2 <- p2 + 
  annotate("text", x = 3.30, y = 1.15, label = "non-CCP member", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 6.0, y = 0.9, label = "member", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure A6.pdf", width = 8, height = 8)

### Figure A7: public approval across experimental conditions, by income ----
## Create an empty data frame to store the results
df_mean_approval_US_inc <- df_mean_approval_CN_inc <- data.frame(matrix(ncol = 6, nrow = 18))
x <- c("condition", "mean", "ci_lower", "ci_upper", "n", "income")
colnames(df_mean_approval_US_inc) <- colnames(df_mean_approval_CN_inc) <- x
df_mean_approval_US_inc$condition <- df_mean_approval_CN_inc$condition <- 1:18

## Extract mean and CIs
for (i in 1:4) {
  # American sample
  temp_US_inc <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (income_over_50k == 1))
  df_mean_approval_US_inc[i + 1, 2:5] <- 
    c(temp_US_inc$coefficients, temp_US_inc$conf.low, temp_US_inc$conf.high, temp_US_inc$df + 1)
  df_mean_approval_US_inc[i + 1, 6] <- "Income over Median"
  temp_US_lessinc <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (income_over_50k == 0))
  df_mean_approval_US_inc[i + 5, 2:5] <- 
    c(temp_US_lessinc$coefficients, temp_US_lessinc$conf.low, temp_US_lessinc$conf.high, temp_US_lessinc$df + 1)
  df_mean_approval_US_inc[i + 5, 6] <- "Income below Median"
  
  # Chinese sample
  temp_CN_inc <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (income_over_50k == 1))
  df_mean_approval_CN_inc[i + 1, 2:5] <- 
    c(temp_CN_inc$coefficients, temp_CN_inc$conf.low, temp_CN_inc$conf.high, temp_CN_inc$df + 1)
  df_mean_approval_CN_inc[i + 1, 6] <- "Income over Median"
  temp_CN_lessinc <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (income_over_50k == 0))
  df_mean_approval_CN_inc[i + 5, 2:5] <- 
    c(temp_CN_lessinc$coefficients, temp_CN_lessinc$conf.low, temp_CN_lessinc$conf.high, temp_CN_lessinc$df + 1)
  df_mean_approval_CN_inc[i + 5, 6] <- "Income below Median"
}

for (i in 5:8) {
  # American sample
  temp_US_inc <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (income_over_50k == 1))
  df_mean_approval_US_inc[i + 6, 2:5] <- 
    c(temp_US_inc$coefficients, temp_US_inc$conf.low, temp_US_inc$conf.high, temp_US_inc$df + 1)
  df_mean_approval_US_inc[i + 6, 6] <- "Income over Median"
  temp_US_lessinc <- lm_robust(approval ~ 1, data = df_US, subset = (des == i) & (income_over_50k == 0))
  df_mean_approval_US_inc[i + 10, 2:5] <- 
    c(temp_US_lessinc$coefficients, temp_US_lessinc$conf.low, temp_US_lessinc$conf.high, temp_US_lessinc$df + 1)
  df_mean_approval_US_inc[i + 10, 6] <- "Income below Median"
  
  # Chinese sample
  temp_CN_inc <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (income_over_50k == 1))
  df_mean_approval_CN_inc[i + 6, 2:5] <- 
    c(temp_CN_inc$coefficients, temp_CN_inc$conf.low, temp_CN_inc$conf.high, temp_CN_inc$df + 1)
  df_mean_approval_CN_inc[i + 6, 6] <- "Income over Median"
  temp_CN_lessinc <- lm_robust(approval ~ 1, data = df_CN, subset = (des == i) & (income_over_50k == 0))
  df_mean_approval_CN_inc[i + 10, 2:5] <- 
    c(temp_CN_lessinc$coefficients, temp_CN_lessinc$conf.low, temp_CN_lessinc$conf.high, temp_CN_lessinc$df + 1)
  df_mean_approval_CN_inc[i + 10, 6] <- "Income below Median"
}

## Visualize the results for the American sample
df_mean_approval_US_inc$condition <- 
  factor(df_mean_approval_US_inc$condition, levels = c(1:18),
         labels = c("US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs"))
df_mean_approval_US_inc$condition <- factor(df_mean_approval_US_inc$condition, 
                                            levels = rev(levels(df_mean_approval_US_inc$condition)))
df_mean_approval_US_inc$color <- factor(rep(c(0, rep(1:4, 2)), 2))
df_mean_approval_US_inc$income <- factor(df_mean_approval_US_inc$income,
                                         levels = c("Income over Median", "Income below Median"))
p1 <- ggplot(df_mean_approval_US_inc, aes(x = mean, y = condition, color = color, 
                                          shape = income, linetype = income)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("American Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p1 <- p1 + 
  annotate("text", x = 2.08, y = 1.15, label = "income below 50k", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 4.55, y = 0.9, label = "income above 50k", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Visualize the results for the Chinese sample
df_mean_approval_CN_inc$condition <- 
  factor(df_mean_approval_CN_inc$condition, levels = c(1:18),
         labels = c("China as First Mover",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US Removes $150 Billion", "US Removes $100 Billion",
                    "US Removes $50 Billion", "US Does Not Remove Tariffs",
                    "US as First Mover",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs",
                    "China Removes $150 Billion", "China Removes $100 Billion",
                    "China Removes $50 Billion", "China Does Not Remove Tariffs"))
df_mean_approval_CN_inc$condition <- factor(df_mean_approval_CN_inc$condition, 
                                            levels = rev(levels(df_mean_approval_CN_inc$condition)))
df_mean_approval_CN_inc$color <- factor(rep(c(0, rep(1:4, 2)), 2))
df_mean_approval_CN_inc$income <- factor(df_mean_approval_CN_inc$income,
                                         levels = c("Income over Median", "Income below Median"))
p2 <- ggplot(df_mean_approval_CN_inc, aes(x = mean, y = condition, color = color, 
                                          shape = income, linetype = income)) +
  geom_point(size = 2, position = position_dodge(width = 0.5)) +
  scale_color_manual(values = c("black", "black", "black", "black", "black")) +
  scale_shape_manual(values = c(19, 17, 21)) +
  geom_errorbar(aes(xmin = ci_lower, xmax = ci_upper), size = .7, width = 0, position = position_dodge(width = 0.5)) +
  ylab("") +
  xlab("Seven-Point Approval\n") +
  theme_classic() +
  coord_cartesian(xlim = c(0, 6)) +
  ggtitle("Chinese Sample") +
  geom_vline(xintercept = 3, color = "grey40", linetype = "dashed") +
  theme(legend.position = "none",
        text = element_text(color = "black", size = 15, family = "Times"),
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(face = c('plain', 'plain', 'plain', 'plain', 'bold',
                                            'plain', 'plain', 'plain', 'plain', 'bold')),
        plot.title = element_text(hjust = 0.5, face = "italic")) +
  guides(color = "none", shape = "none")
p2 <- p2 + 
  annotate("text", x = 3.39, y = 1.15, label = "income below 50k", 
           size = 4, color = "black", fontface = "italic", family = "Times") +
  annotate("text", x = 5.65, y = 0.9, label = "income above 50k", 
           size = 4, color = "black", fontface = "italic", family = "Times")

## Combine into one graph
plot_grid(p1, p2, labels = "AUTO", ncol = 1, label_fontfamily = "Times")
ggsave(file = "Figure A7.pdf", width = 8, height = 8)
